package com.soup.bytebuddy;

import com.soup.bytebuddy.intercept.MonitorConsuming;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.matcher.ElementMatchers;

import java.lang.instrument.Instrumentation;

/**
 * 〈一句话功能简述〉<br>
 *
 * @author 19041060
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class PreMainExistedMethod {

    public static void premain(String arguments,
                               Instrumentation instrumentation) {
        new AgentBuilder.Default()
                // 匹配被拦截方法
                .type(ElementMatchers.nameEndsWith("Timed"))
                .transform((builder, type, classLoader, module) ->
                                builder.method(ElementMatchers.any()).intercept(MethodDelegation.to(MonitorConsuming.class))
                ).installOn(instrumentation);
    }
}
